import itertools
a = 'LOA'
b = 5
def panduan(aa):
    lens = len(aa)
    for i in xrange(lens -2):
        if aa[i] == aa[i+1] == aa[i+2] == "A":
            return True
    return False

jiangli = []
for cc in itertools.product(a, repeat=b):
    temp = cc.count("L")
    if temp > 1: 
        continue
    if panduan(cc):
        continue
    print cc
    jiangli.append(cc)

# print(jiangli)
print(len(jiangli))